﻿using System.Resources;


namespace HappyTemplate
{
	//TODO:  refactor error collectors to use this base instead of providing their own
	//impelementation of Add(SourceLocaiton, string int, param object[])...
	abstract class ErrorCollectorBase
	{
		SourceErrorCollection _sourceErrors;

		public SourceErrorCollection SourceErrors { get { return _sourceErrors; } set { _sourceErrors = value; } }

		protected ErrorCollectorBase(SourceErrorCollection sourceErrors)
		{
			_sourceErrors = sourceErrors;
		}

		protected abstract ResourceManager MessageResourceManager { get; }

		protected void Add(SourceLocation loc, string messageName, params object[] args)
		{
			string msgfmt = this.MessageResourceManager.GetString(messageName);
			DebugAssert.IsNotNull(msgfmt, "Error message \"{0}\" not found in resources", messageName);
			SourceError sec = new SourceError(loc, StringHelp.Format(msgfmt, args));
			_sourceErrors.Add(sec);
		}
	}
}
